package com.yonyou.pmclouds.problemlog.service.rmiimpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.ref.itf.RefCodeConst;
import com.yonyou.pmclouds.basecom.ref.itf.ReferenceCheckOfBusiness;
import com.yonyou.pmclouds.problemlog.entity.ProblemLogVO;
import com.yonyou.pmclouds.problemlog.service.rmiitf.ProblemLogQuery;
@Component
public class ReferenceCheckOfProblemLog implements ReferenceCheckOfBusiness{
    @Autowired
    private ProblemLogQuery query;
    @Override
    public String[] getReferenceCode() {
        return new String[]{RefCodeConst.PROJECT,RefCodeConst.PROCEDURE,RefCodeConst.PROBLEM_REASON,RefCodeConst.PROJECTPART};
    }

    @Override
    public boolean checkReferenced(String bdCode, String[] keys) throws BusinessException {
        String code = null;
        if(RefCodeConst.PROJECT.equals(bdCode)) {
            code = ProblemLogVO.PK_PROJECT;
        } else if(RefCodeConst.PROCEDURE.equals(bdCode)) {
            code = ProblemLogVO.PK_PROCESS;
        } else if(RefCodeConst.PROBLEM_REASON.equals(bdCode)) {
            code = ProblemLogVO.PK_PROBLEMREASON;
        }else if(RefCodeConst.PROJECTPART.equals(bdCode)) {
            code = ProblemLogVO.PK_PROJECTPART;
        } else {
            throw new BusinessException("问题记录单暂未引用该档案!");
       }
       return query.queryRefByIds(code, keys);
    }

}
